package com.algorithm;

public class Solution {
    public static void main(String[] args) {
        Solution1 abc = new Solution1();
        String abcd = abc.addBinary("11", "1");
        System.out.println("结果"+Integer.parseInt(abcd));
    }

    static class Solution1 {
        public String addBinary(String a, String b) {
            StringBuilder ans = new StringBuilder();
            int ca = 0;
            for (int i = a.length() - 1, j = b.length() - 1; i >= 0 || j >= 0; i--, j--) {
                int sum = ca;
                sum += i >= 0 ? a.charAt(i) - '0' : 0;
                sum += j >= 0 ? b.charAt(j) - '0' : 0;
                ans.append(sum % 2);
                ca = sum / 2;
            }
            ans.append(ca == 1 ? ca : "");
            return ans.reverse().toString();
        }
    }
}
